from jsonpath_ng import parse
from
test_data = {
    "store": {
        "book": [
            {"title": "语文", "price": 80},
            {"title": "数学", "price": 50}
        ]
    }
}

expr = parse('$.store.book[*].title')
matches = [match.value for match in expr.find(test_data)]
print(matches)


# def file_read(cls, file_path):
#
#
#    file = []
#
#    if m in
#
# def data_read(cls,obj):
#
# class localJSONValidator(JSONDataValidator):
#     a

test_data = []

for key in mode:
    sheet = wb[key]
    if mode[key] == 'all':
        for i in range(2, sheet.max_row + 1):
            row_data = {}
            row_data['case_id'] = sheet.cell(i, 1).value
            row_data['url'] = sheet.cell(i, 2).value
            # row_data['data'] = sheet.cell(i, 3).value
            if sheet.cell(i, 3).value.find('${tel}') != -1:  # 查找值，如果有
                row_data['data'] = sheet.cell(i, 3).value.replace('${tel}', str(tel))
                # row_data['data'] = sheet.cell(i, 3).value.replace('${tel_1}', str(getattr(GetData,'NoRegTel')))
                tel += 1
            if sheet.cell(i, 3).value.find('${normal_email}') != -1:
                row_data['data'] = sheet.cell(i, 3).value.replace('${normal_email}',
                                                                  str(getattr(GetData, 'normal_email')))
            if sheet.cell(i, 3).value.find('${email_password}') != -1:
                row_data['data'] = row_data['data'].replace('${email_password}',
                                                            str(getattr(GetData, 'email_password')))
            elif sheet.cell(i, 3).value.find('${courseid}') != -1:
                row_data['data'] = sheet.cell(i, 3).value.replace('${courseid}',
                                                                  str(getattr(GetData, 'courseid')))
            elif sheet.cell(i, 3).value.find('${fromclassid}') != -1:
                row_data['data'] = sheet.cell(i, 3).value.replace('${fromclassid}',
                                                                  str(getattr(GetData, 'fromclassid')))
            elif sheet.cell(i, 3).value.find('${classid}') != -1:
                row_data['data'] = sheet.cell(i, 3).value.replace('${classid}',
                                                                  str(getattr(GetData, 'classid')))
            else:
                row_data['data'] = sheet.cell(i, 3).value
            row_data['title'] = sheet.cell(i, 4).value
            row_data['http_method'] = sheet.cell(i, 5).value
            row_data['response'] = sheet.cell(i, 6).value
            row_data['expected'] = sheet.cell(i, 7).value
            row_data['result'] = sheet.cell(i, 8).value
            row_data['sheet_name'] = key
            test_data.append(row_data)
            cls.update_test_data(tel, file_name, 'init')  # 更新手机号，针对excel文件数据
            # 另一种遍历替换方式
            # for item in test_data:
            #     if item['data']['mobilephone'] == '${tel}':
            #         #替换数据
    else:
        for case_id in mode[key]:
            row_data = {}
            row_data['case_id'] = sheet.cell(case_id + 1, 1).value
            row_data['url'] = sheet.cell(case_id + 1, 2).value
            if sheet.cell(case_id, 3).valud.find('${tel}') != -1:
                row_data['data'] = sheet.cell(case_id + 1, 3).value.replace('${tel}',
                                                                            str(getattr(GetData, 'tel')))
                tel += 1
            elif sheet.cell(case_id, 3).value.find('${normal_email}') != -1:
                row_data['data'] = sheet.cell(case_id, 3).value.replace('${normal_email}',
                                                                        str(getattr(GetData, 'normal_email')))
            elif sheet.cell(case_id, 3).value.find('${normal_email}') != -1:
                row_data['data'] = sheet.cell(case_id, 3).value.replace(GetData,
                                                                        str(getattr(GetData, 'email_password')))
                print(sheet.cell(i, 3))
            elif sheet.cell(case_id, 3).value.find('${courseid}') != -1:
                row_data['data'] = sheet.cell(case_id, 3).value.replace(GetData,
                                                                        str(getattr(GetData, '${courseid}')))
            elif sheet.cell(case_id, 3).value.find('${fromclassid}') != -1:
                row_data['data'] = sheet.cell(case_id, 3).value.replace(GetData,
                                                                        str(getattr(GetData, '${fromclassid}')))
            elif sheet.cell(case_id, 3).value.find('${classid}') != -1:
                row_data['data'] = sheet.cell(case_id, 3).value.replace(GetData,
                                                                        str(getattr(GetData, '${classid}')))
            else:
                row_data['data'] = sheet.cell(case_id, 3).value
            row_data['title'] = sheet.cell(case_id, 4).value
            row_data['http_method'] = sheet.cell(case_id, 5).value
            row_data['response'] = sheet.cell(case_id, 6).value
            row_data['expected'] = sheet.cell(case_id, 7).value
            row_data['result'] = sheet.cell(case_id, 8).value
            row_data['sheet_name'] = key
            test_data.append(row_data)
return test_data